1. /* sdfatans.cpp by K.Tsuru */
  2. // function ID = 3603 DARDIX
  3. /***************************************************************
  4. SDouble class
  5. inverse trigonometric function arctan x using series expansion
  6. arctan x = x - x^3/3 + x^5/5 -.... (|x|<1.0).
  7. Please use for a very small value |x|.
  8. See AsinSeries() for the meaning of "fe".
  9. Not default argument.
  10. *****************************************************************/
  11. #ifndef SN_H
  12. #include "sn.h"
  13. #endif
  14. static const char* func = "AtanSeries";
  15. SDouble AtanSeries(const SDouble& x, int fe){
  16. if(x.NetRdxExp() > 0) x.SetError(x.OUT_OF_RANGE, func, 3603); // |x| > 1.0
  17. SDouble sum(x), xn(x), xsq(x*x), delta;
  18. ulong n = 1uL, mt = sum.SlOpMaxValue();
  19. sum.FixedPoint(fe);
  20. do{
  21. xn *= xsq;
  22. n += 2uL;
  23. if(n > mt){
  24. sum.SetError(sum.NOT_CONVERGE, func, -3603);
  25. break;
  26. }
  27. delta = DsDiv(xn, n);
  28. if(n & 2uL) sum -= delta; // n = 3, 7, 11, ...
  29. else sum += delta; // n = 5, 9, 13
  30. } while(delta.Sign(3603));
  31. sum.PointFree();
  32. sum.Reform(3603);
  33. sum.upToTerm = (n+1uL)/2uL;
  34. return sum;
  35. }

sdfatans.cpp : last modifiled at 2015/12/03 21:32:43(1,097 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).